package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 韩先楚
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "用户购物车模块")
@Slf4j
public class ShopingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

/**
 * 添加购物车
 * @return
 */
    @PostMapping("/add")
    @ApiOperation(value = "添加购物车", notes = "添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        log.info("添加购物车：{}",shoppingCartDTO);
        shoppingCartService.addCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查询用户的购物车
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询用户的购物车", notes = "查询用户的购物车")
    public Result<List<ShoppingCart>> list()
    {
        log.info("查询用户的购物车");
     List<ShoppingCart> shoppingCarts = shoppingCartService.list();
     return Result.success(shoppingCarts);
    }

    /**
     *
     * 清空购物车
     */
    @DeleteMapping("/clean")
    @ApiOperation(value = "清空购物车", notes = "清空购物车")
    public Result clean()
    {
        log.info("清空购物车");
        shoppingCartService.clean();
        return Result.success();
    }

}
